# 随机种植
# 据说，随机种植的产量会比全种某个植物产量更高，我也不知道真的假的，你们可以试试
import common
plant_type_list = [Entities.Grass,Entities.Tree,Entities.Carrot]
while True:
	size = get_world_size()
	drons = max_drones()
	if size % drons != 0 :
		size = size - (size % drons)
		set_world_size(size)
	alldrons = []
	
	for n in range(drons):
		def plant_and_havest():
			while True:
				
				for i in range(size/drons):
					for y in range(size):
						x = n * size/drons  +i 
						common.move_abs(x,y)
						
						if get_water() < 0.5:
							use_item(Items.Water)
						if get_ground_type() != Grounds.Soil:
							till()
							
							plant(plant_type_list[random()*len(plant_type_list)])
							
							
						if can_harvest():
							harvest()
							r = random()*len(plant_type_list)
							plant(plant_type_list[r])
		d = spawn_drone(plant_and_havest)
		if d :
			alldrons.append(d)
		else:
			plant_and_havest()
	for d in alldrons:
		if not has_finished(d):
			wait_for(d)
	harvest()